package com.xt.LibaryDeskManager.service.impl;

import com.xt.LibaryDeskManager.dao.SeatMapper;
import com.xt.LibaryDeskManager.dto.SeatDto;
import com.xt.LibaryDeskManager.service.SeatService;
import com.xt.LibaryDeskManager.vo.SeatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 童归权
 * @version 1.0 2021/2/7
 */
@Service
public class SeatServiceImpl implements SeatService {
    @Autowired
    private SeatMapper seatMapper;

    @Override
    public List<SeatDto> selectAll(String seatNo) throws Exception {
        return seatMapper.selectLike(seatNo);
    }

    @Override
    public List<SeatDto> selectAll(Integer teacherNo,String seatNo) throws Exception {
        return seatMapper.selectAllByTeacher(teacherNo,seatNo);
    }

    @Override
    public int getCount() throws Exception {
        return seatMapper.getCount();
    }

    @Override
    public int updateSeat(SeatVo seatVo) throws Exception {
        return seatMapper.updateSeat(seatVo);
    }

    @Override
    public int updateSeatStatue(String seatNo, int i)throws Exception {
        return seatMapper.updateSeatStatue(seatNo,i);
    }

    @Override
    public SeatDto getSeatBySeatNo(String seatNo) throws Exception {
        return seatMapper.getSeatBySeatNo(seatNo);
    }

    @Override
    public int updateSeat() throws Exception {
        return  seatMapper.updateSeat1();
    }

    @Override
    public String getAvailableSeatNumber(String seatNo) throws Exception {
        SeatDto s1= seatMapper.getAvailableSeatNumber(seatNo);
        if (s1!=null){
            String a=s1.getSeatNo();
            String b=a.substring(a.length()-2,a.length());
            return String.valueOf(Integer.parseInt(b)+1);
        }else{
          return "000";
        }
    }

    @Override
    public int addSeat(SeatVo seatVo) throws Exception {
        return seatMapper.addSeat(seatVo);
    }

    @Override
    public int deleteSeat(String seatNo) throws Exception {
        return seatMapper.deleteSeat(seatNo);
    }

}
